package com.seeingtv.common.utils.xml;

import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import java.util.regex.Pattern;

/**
 * Implementation which is able to decide to use a CDATA section for a string.
 * 测试对C2格式的xml加CDATA无效
 */
public class CDataXMLStreamWriter extends DelegatingXMLStreamWriter {
	//正则匹配
	private static final String REG_EX = "[&<>]";
	private static final Pattern XML_CHARS = Pattern.compile(REG_EX);

	public CDataXMLStreamWriter(XMLStreamWriter del) {
		super(del);
	}

	@Override
	public void writeCharacters(String text) throws XMLStreamException {
//		boolean useCData = XML_CHARS.matcher(text).find();
//		if (useCData) {
			//加标签
			super.writeCData(text);
//		} else {
//			//不加标签
//			super.writeCharacters(text);
//		}
	}
}